package com.ag.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbEvent;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbEvent entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.ag.bean.TbEvent
 * @author MyEclipse Persistence Tools
 */

public class TbEventDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbEventDAO.class);
	// property constants
	public static final String _EEVENTNAME = "EEventname";
	public static final String _EEVENT_ADDR = "EEventAddr";
	public static final String _ELONGITUDE = "ELongitude";
	public static final String _ELATITUDE = "ELatitude";
	public static final String _EEVENT_CAUSE = "EEventCause";
	public static final String _EEVENT_DESC = "EEventDesc";
	public static final String _ETAKE_MEASURE = "ETakeMeasure";
	public static final String _EDEATHS = "EDeaths";
	public static final String _EINJURIES = "EInjuries";
	public static final String _ESUBMITER = "ESubmiter";
	public static final String _ESUBMIT_DEPT = "ESubmitDept";
	public static final String _ESUBMITER_CONTACT = "ESubmiterContact";
	public static final String _ENOTIFY_LEADER = "ENotifyLeader";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";

	protected void initDao() {
		// do nothing
	}

	public void save(TbEvent transientInstance) {
		log.debug("saving TbEvent instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbEvent persistentInstance) {
		log.debug("deleting TbEvent instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbEvent findById(java.lang.String id) {
		log.debug("getting TbEvent instance with id: " + id);
		try {
			TbEvent instance = (TbEvent) getHibernateTemplate().get(
					"com.ag.bean.TbEvent", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbEvent> findByExample(TbEvent instance) {
		log.debug("finding TbEvent instance by example");
		try {
			List<TbEvent> results = (List<TbEvent>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbEvent instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbEvent as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbEvent> findByEEventname(Object EEventname) {
		return findByProperty(_EEVENTNAME, EEventname);
	}

	public List<TbEvent> findByEEventAddr(Object EEventAddr) {
		return findByProperty(_EEVENT_ADDR, EEventAddr);
	}

	public List<TbEvent> findByELongitude(Object ELongitude) {
		return findByProperty(_ELONGITUDE, ELongitude);
	}

	public List<TbEvent> findByELatitude(Object ELatitude) {
		return findByProperty(_ELATITUDE, ELatitude);
	}

	public List<TbEvent> findByEEventCause(Object EEventCause) {
		return findByProperty(_EEVENT_CAUSE, EEventCause);
	}

	public List<TbEvent> findByEEventDesc(Object EEventDesc) {
		return findByProperty(_EEVENT_DESC, EEventDesc);
	}

	public List<TbEvent> findByETakeMeasure(Object ETakeMeasure) {
		return findByProperty(_ETAKE_MEASURE, ETakeMeasure);
	}

	public List<TbEvent> findByEDeaths(Object EDeaths) {
		return findByProperty(_EDEATHS, EDeaths);
	}

	public List<TbEvent> findByEInjuries(Object EInjuries) {
		return findByProperty(_EINJURIES, EInjuries);
	}

	public List<TbEvent> findByESubmiter(Object ESubmiter) {
		return findByProperty(_ESUBMITER, ESubmiter);
	}

	public List<TbEvent> findByESubmitDept(Object ESubmitDept) {
		return findByProperty(_ESUBMIT_DEPT, ESubmitDept);
	}

	public List<TbEvent> findByESubmiterContact(Object ESubmiterContact) {
		return findByProperty(_ESUBMITER_CONTACT, ESubmiterContact);
	}

	public List<TbEvent> findByENotifyLeader(Object ENotifyLeader) {
		return findByProperty(_ENOTIFY_LEADER, ENotifyLeader);
	}

	public List<TbEvent> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbEvent> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbEvent> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List findAll() {
		log.debug("finding all TbEvent instances");
		try {
			String queryString = "from TbEvent";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbEvent merge(TbEvent detachedInstance) {
		log.debug("merging TbEvent instance");
		try {
			TbEvent result = (TbEvent) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbEvent instance) {
		log.debug("attaching dirty TbEvent instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbEvent instance) {
		log.debug("attaching clean TbEvent instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbEventDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TbEventDAO) ctx.getBean("TbEventDAO");
	}
}